home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!longbarn.demon.co.uk
- From: Peter Jones <pete@longbarn.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Mouse Routines using C/C++
- Date: Sat, 20 Jan 1996 17:26:36 GMT
- Organization: None
- Message-ID: <327416772wnr@longbarn.demon.co.uk>
- Reply-To: pete@longbarn.demon.co.uk
- X-NNTP-Posting-Host: longbarn.demon.co.uk
- X-Broken-Date: Saturday, Jan 20, 1996 17.26.36
- X-Newsreader: Newswin Alpha 0.7
- X-Mail2News-Path: relay-4.mail.demon.net!post.demon.co.uk!longbarn.demon.co.uk
-
- //Here's some C++ code for mice for DOS:
-
- class Mouse
- {
- private:
- int got_mouse, // Mouse init flag.
- num_buttons; // # buttons on mouse.
- public:
- Mouse(void);
- ~Mouse(void);
- int GotMouse(void) {return got_mouse;}
- void PutMouse(int x,int y);
- void SetLimits(int minXLimit, int maxXLimit, int minYLimit, int maxYLimit);
- void ShowMouse(void);
- void HideMouse(void);
- int Button(void);
- int NumButtons(void) {return num_buttons;}
- int WhereX(void);
- int WhereY(void);
- };
-
- Mouse::Mouse(void)
- {
- got_mouse = 0;
- int a,b;
- _asm{
- MOV AX,0x0000
- INT 33h
- MOV a,AX
- MOV b,BX
- }
- got_mouse=a;
- num_buttons=b;
- }
-
- Mouse::~Mouse(void)
- {
- _asm{
- MOV AX,0x0000
- INT 33h
- }
- }
-
-
- void Mouse::PutMouse(int x,int y)
- {
- _asm{
- MOV AX,0x0004
- MOV CX,x
- MOV DX,y
- INT 33h
- }
- }
-
- void Mouse::SetLimits(int minXLimit, int maxXLimit,
- int minYLimit, int maxYLimit)
- {
- _asm{
- MOV AX,0x0007
- MOV CX,minXLimit
- MOV DX,maxXLimit
- INT 33h
- MOV AX,0x0008
- MOV CX,minYLimit
- MOV DX,maxYLimit
- INT 33h
- }
- }
-
- void Mouse::ShowMouse(void)
- {
- if (!got_mouse)
- return;
- _asm{
- MOV AX,0x0001
- INT 33h
- }
- }
-
- void Mouse::HideMouse(void)
- {
- if (!got_mouse)
- return;
- _asm{
- MOV AX,0x0002
- INT 33h
- }
- }
-
- int Mouse::Button(void)
- {
- int a;
- _asm{
- MOV AX,0x0003
- INT 33h
- MOV a,BX
- }
- return a;
- }
-
- int Mouse::WhereX(void)
- {
- int a;
- _asm{
- MOV AX,0x0003
- INT 33h
- MOV a,CX
- }
- return a;
- }
-
- int Mouse::WhereY(void)
- {
- int a;
- _asm{
- MOV AX,0x0003
- INT 33h
- MOV a,DX
- }
- return a;
- }
-
- #include <conio.h>
-
- int main(void)
- {
- Mouse mouse;
-
- int x,y;
-
- if(!mouse.GotMouse())
- {
- cprintf("No mouse found!");
- return 1;
- }
-
- mouse.ShowMouse();
-
- cprintf("%d buttons found\n\r",mouse.NumButtons());
-
- while(!mouse.Button())
- {
- cprintf("The mouse is at (%2d,%2d)\r",mouse.WhereX()/8,mouse.WhereY()/8);
- // Remember to divide any co-ords by 8 when in text mode.
- }
-
- cprintf("\n\rButton pressed!");
-
- mouse.HideMouse();
-
- return 0;
- }
-
- // I hope this is of some use.
-
- --
- /-------------------------------------------------------------------------\
- | Peter Jones pete@longbarn.demon.co.uk |
- \-------------------------------------------------------------------------/
-
-